package com.tjrac.zhaopin;

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class SendMail {
    private final String MAIL_NAME = "85901009@qq.com";
    private final String MAIL_AUTH = "bzssclwkquylbjac";
    public SendMail(){
        Properties properties = new Properties();
        properties.setProperty("mail.smtp.host","smtp.qq.com");
        properties.setProperty("mail.smtp.port","465");
        properties.setProperty("mail.smtp.auth","true");
        properties.setProperty("mail.debug","true");
        properties.setProperty("mail.transport","smtp");
        properties.setProperty("mail.smtp.ssl.enable","true");
        Session session = Session.getInstance(properties, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(MAIL_NAME,MAIL_AUTH);
            }
        });
        Message message = new MimeMessage(session);
        try {
            message.setFrom(new InternetAddress("85901009@qq.com"));
            message.setRecipient(Message.RecipientType.TO,new InternetAddress("85901009@qq.com"));
            message.setSubject("仁爱招聘网——密码找回");
            message.setContent("您的验证码是：7355608，此验证码将作为您所找回密码的唯一凭据！","text/html;charset=UTF-8");
            Transport transport = session.getTransport();
            transport.connect(MAIL_NAME,MAIL_AUTH);
            Transport.send(message);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}
